<template>
	<view class="bg-white">
		<view class="login">
			<u-field label-width="240" input-align="right" label="企业名称" placeholder="" v-model="company_name"></u-field>
			<u-field label-width="240" input-align="right" label="法定代表人姓名" placeholder="" v-model="corporation"></u-field>
		</view>

		<u-gap height="24" bg-color="#f5f5f5"></u-gap>

		<view style="padding: 40rpx;">
			<view>营业执照上传<text class="text-xs">（上传图片要求文字清晰可识别）</text></view>
			<u-upload :show-progress="false" upload-text="上传图片" :action="$store.state.upload" :header="{Authorization: 'Bearer ' + $store.state.token}"
			 :form-data="{type: 'license'}" :max-count="1" @on-success="success" @on-remove="bussiness_license=''"></u-upload>
		</view>

		<my-btn gold :disabled="!canSubmit" style="margin: 60rpx auto;" @click="submit">认证</my-btn>
		<u-gap height="10"></u-gap>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				company_name: '',
				corporation: '',
				bussiness_license: ''
			};
		},
		computed: {
			canSubmit() {
				if (this.company_name && this.corporation && this.bussiness_license) {
					return true
				} else {
					return false
				}
			}
		},
		methods: {
			success(e) {
				if (e.code==0) {
					this.bussiness_license = e.result.src
				}
			},
			submit() {
				this.$u.post('/member/usage', {
					company_name: this.company_name,
					corporation: this.corporation,
					bussiness_license: this.bussiness_license
				}).then(res => {
					if (res.data.code == 0) {
						uni.showLoading({
							title: '提交成功...',
							mask: true
						})
						this.$u.api.getUserinfo().then(res => {
							this.$goto('/pages/user/index', 'redirect')
						})
					} else {
						this.$msg(res.data.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.u-field {
		padding: 28rpx 40rpx;
	}
	
	/deep/ .u-list-item {
		margin: 24rpx 0;
	}
</style>
